from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-14 14:11:07.561047
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 14, Sep, 2022
Time: 14:11:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4107
Nobs: 779.000 HQIC: -50.7418
Log likelihood: 9986.39 FPE: 7.46814e-23
AIC: -50.9488 Det(Omega_mle): 6.65820e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298891 0.054145 5.520 0.000
L1.Burgenland 0.108690 0.036062 3.014 0.003
L1.Kärnten -0.106580 0.019174 -5.559 0.000
L1.Niederösterreich 0.207410 0.075438 2.749 0.006
L1.Oberösterreich 0.106939 0.072974 1.465 0.143
L1.Salzburg 0.252006 0.038510 6.544 0.000
L1.Steiermark 0.038199 0.050310 0.759 0.448
L1.Tirol 0.106006 0.040787 2.599 0.009
L1.Vorarlberg -0.059596 0.035096 -1.698 0.089
L1.Wien 0.052453 0.064948 0.808 0.419
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059080 0.112315 0.526 0.599
L1.Burgenland -0.035137 0.074805 -0.470 0.639
L1.Kärnten 0.047547 0.039773 1.195 0.232
L1.Niederösterreich -0.177291 0.156484 -1.133 0.257
L1.Oberösterreich 0.397392 0.151372 2.625 0.009
L1.Salzburg 0.288253 0.079882 3.608 0.000
L1.Steiermark 0.107172 0.104361 1.027 0.304
L1.Tirol 0.313403 0.084607 3.704 0.000
L1.Vorarlberg 0.027190 0.072800 0.373 0.709
L1.Wien -0.020550 0.134724 -0.153 0.879
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191131 0.027807 6.873 0.000
L1.Burgenland 0.089676 0.018520 4.842 0.000
L1.Kärnten -0.008420 0.009847 -0.855 0.393
L1.Niederösterreich 0.262874 0.038743 6.785 0.000
L1.Oberösterreich 0.130030 0.037477 3.470 0.001
L1.Salzburg 0.047007 0.019777 2.377 0.017
L1.Steiermark 0.018051 0.025838 0.699 0.485
L1.Tirol 0.093549 0.020947 4.466 0.000
L1.Vorarlberg 0.058941 0.018024 3.270 0.001
L1.Wien 0.118186 0.033355 3.543 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110330 0.028362 3.890 0.000
L1.Burgenland 0.045223 0.018889 2.394 0.017
L1.Kärnten -0.015314 0.010043 -1.525 0.127
L1.Niederösterreich 0.195010 0.039515 4.935 0.000
L1.Oberösterreich 0.287948 0.038224 7.533 0.000
L1.Salzburg 0.114368 0.020172 5.670 0.000
L1.Steiermark 0.101877 0.026353 3.866 0.000
L1.Tirol 0.113082 0.021365 5.293 0.000
L1.Vorarlberg 0.069653 0.018383 3.789 0.000
L1.Wien -0.022723 0.034020 -0.668 0.504
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132588 0.051514 2.574 0.010
L1.Burgenland -0.051331 0.034309 -1.496 0.135
L1.Kärnten -0.039817 0.018242 -2.183 0.029
L1.Niederösterreich 0.172454 0.071772 2.403 0.016
L1.Oberösterreich 0.135332 0.069427 1.949 0.051
L1.Salzburg 0.285978 0.036638 7.806 0.000
L1.Steiermark 0.035528 0.047865 0.742 0.458
L1.Tirol 0.161249 0.038805 4.155 0.000
L1.Vorarlberg 0.101321 0.033390 3.034 0.002
L1.Wien 0.068663 0.061791 1.111 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058825 0.040943 1.437 0.151
L1.Burgenland 0.039046 0.027269 1.432 0.152
L1.Kärnten 0.051226 0.014499 3.533 0.000
L1.Niederösterreich 0.223551 0.057044 3.919 0.000
L1.Oberösterreich 0.281780 0.055181 5.106 0.000
L1.Salzburg 0.048898 0.029120 1.679 0.093
L1.Steiermark -0.004152 0.038043 -0.109 0.913
L1.Tirol 0.147469 0.030842 4.781 0.000
L1.Vorarlberg 0.072728 0.026538 2.741 0.006
L1.Wien 0.081528 0.049112 1.660 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180731 0.048928 3.694 0.000
L1.Burgenland -0.006480 0.032587 -0.199 0.842
L1.Kärnten -0.061174 0.017326 -3.531 0.000
L1.Niederösterreich -0.084216 0.068170 -1.235 0.217
L1.Oberösterreich 0.194799 0.065943 2.954 0.003
L1.Salzburg 0.056495 0.034799 1.623 0.104
L1.Steiermark 0.232289 0.045463 5.109 0.000
L1.Tirol 0.493169 0.036858 13.380 0.000
L1.Vorarlberg 0.048600 0.031714 1.532 0.125
L1.Wien -0.051999 0.058690 -0.886 0.376
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166705 0.056129 2.970 0.003
L1.Burgenland -0.009432 0.037383 -0.252 0.801
L1.Kärnten 0.067106 0.019876 3.376 0.001
L1.Niederösterreich 0.203875 0.078203 2.607 0.009
L1.Oberösterreich -0.073777 0.075648 -0.975 0.329
L1.Salzburg 0.211928 0.039921 5.309 0.000
L1.Steiermark 0.117314 0.052154 2.249 0.024
L1.Tirol 0.072542 0.042282 1.716 0.086
L1.Vorarlberg 0.122457 0.036382 3.366 0.001
L1.Wien 0.122910 0.067328 1.826 0.068
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357721 0.032530 10.997 0.000
L1.Burgenland 0.005981 0.021666 0.276 0.782
L1.Kärnten -0.023536 0.011519 -2.043 0.041
L1.Niederösterreich 0.217622 0.045323 4.802 0.000
L1.Oberösterreich 0.184814 0.043842 4.215 0.000
L1.Salzburg 0.045755 0.023136 1.978 0.048
L1.Steiermark -0.016449 0.030226 -0.544 0.586
L1.Tirol 0.107208 0.024505 4.375 0.000
L1.Vorarlberg 0.073881 0.021085 3.504 0.000
L1.Wien 0.048277 0.039020 1.237 0.216
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041098 0.150608 0.191954 0.157027 0.125596 0.113119 0.066937 0.223661
Kärnten 0.041098 1.000000 -0.002989 0.130968 0.041999 0.095841 0.430561 -0.052785 0.100935
Niederösterreich 0.150608 -0.002989 1.000000 0.338000 0.152632 0.300390 0.107996 0.183802 0.324284
Oberösterreich 0.191954 0.130968 0.338000 1.000000 0.227398 0.332383 0.172372 0.167745 0.267070
Salzburg 0.157027 0.041999 0.152632 0.227398 1.000000 0.146523 0.123982 0.147634 0.134472
Steiermark 0.125596 0.095841 0.300390 0.332383 0.146523 1.000000 0.152956 0.138864 0.079355
Tirol 0.113119 0.430561 0.107996 0.172372 0.123982 0.152956 1.000000 0.113911 0.153623
Vorarlberg 0.066937 -0.052785 0.183802 0.167745 0.147634 0.138864 0.113911 1.000000 0.006462
Wien 0.223661 0.100935 0.324284 0.267070 0.134472 0.079355 0.153623 0.006462 1.000000